package com.imooc.demo.web;

import com.imooc.demo.entity.Area;
import com.imooc.demo.service.IAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 稻草人 on 2018/6/17.
 * RestController注解是ResponseBody注解和Controller注解的组合
 */

@RestController
@RequestMapping(value = "/superadmin")
public class AreaController {

    @Autowired
    private IAreaService areaService;

    /**
     * 获取区域列表
     * @return
     */
    @RequestMapping(value = "listArea",method = RequestMethod.GET)
    private Map<String,Object> listArea(){
        Map<String,Object> modelMap=new HashMap<String,Object>();
        List<Area> list=areaService.getAreaList();
        modelMap.put("areaList",list);
        return modelMap;
    }


    /**
     * 根据id获取区域信息
     * @param areaId
     * @return
     */
    @RequestMapping(value = "getAreaById",method = RequestMethod.GET)
    private Map<String,Object> getAreaById(Integer areaId){
        Map<String,Object> modelMap=new HashMap<String,Object>();
        Area area=areaService.getAreaById(areaId);
        modelMap.put("area",area);
        return modelMap;
    }


    /**
     * 添加区域信息
     * @param area
     * @return
     */
    @RequestMapping(value = "addArea",method = RequestMethod.POST)
    private Map<String,Object> addArea(@RequestBody Area area){
        Map<String,Object> modelMap=new HashMap<String,Object>();
        modelMap.put("success",areaService.addArea(area));
        return modelMap;
    }


    /**
     * 修改区域信息
     * @param area
     * @return
     */
    @RequestMapping(value = "modifyArea",method = RequestMethod.POST)
    private Map<String,Object> modifyArea(@RequestBody Area area){
        Map<String,Object> modelMap=new HashMap<String,Object>();
        modelMap.put("success",areaService.modifyArea(area));
        return modelMap;
    }

    /**
     * 删除区域信息
     * @param areaId
     * @return
     */
    @RequestMapping(value = "removeArea",method = RequestMethod.GET)
    private Map<String,Object> removeArea( Integer areaId){
        Map<String,Object> modelMap=new HashMap<String,Object>();
        modelMap.put("success",areaService.deleteArea(areaId));
        return modelMap;
    }










}
